package com.cy.train.business.controller.admin;

import cn.hutool.core.util.ObjectUtil;
import com.cy.train.common.resp.CommonResp;
import com.cy.train.common.resp.PageResp;
import com.cy.train.business.req.ConfirmOrderQueryReq;
import com.cy.train.business.req.ConfirmOrderDoReq;
import com.cy.train.business.resp.ConfirmOrderQueryResp;
import com.cy.train.business.service.ConfirmOrderService;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/confirm-order")
public class ConfirmOrderAdminController {
    @Autowired
    private ConfirmOrderService confirmOrderService;

    @PostMapping("/save")
    public CommonResp<Object> register(@Valid @RequestBody ConfirmOrderDoReq req) {
        confirmOrderService.save(req);
        return new CommonResp<>();
    }

    @GetMapping("/query-list")
    public CommonResp<PageResp> register(@Valid ConfirmOrderQueryReq req) {
        if(ObjectUtil.isNull(req)) {
            req = new ConfirmOrderQueryReq();
        }
        PageResp<ConfirmOrderQueryResp> resp = confirmOrderService.queryList(req);
        return new CommonResp<>(resp);
    }

    @DeleteMapping("/delete/{id}")
    public CommonResp<Object> delete(@PathVariable Long id) {
        confirmOrderService.delete(id);
        return new CommonResp<>();
    }
}